const path = require('path')
const HtmlWebpackPlugin = require
('html-webpack-plugin') 
const Webpack = require('webpack')
module.exports = {
	mode: 'development',
	entry: './src/index.tsx', 
	output: {
		path: path.resolve(__dirname,'dist'),
    filename: 'bundle.js',
    publicPath: '/'
	},
	devtool: 'source-map',
	devServer: {
		hot: true,
    contentBase:path.join(__dirname,'dist'),
    publicPath:'/',
		// 无法响应的路由会重定向到首页
		historyApiFallback: true
	},
	// 路径解析
	resolve: {
		extensions: ['.ts','.tsx','.js','.jxs']
	},
	module: {
		rules: [
			{
				test: /\.tsx?/,
				loader: 'ts-loader'
			},
			{
				// pre , normal post
				enforce: 'pre',
				test: /\.tsx?/,
				loader: 'source-map-loader'
      },
      {
        test: /\.less$/,
        use: ["style-loader","css-loader","less-loader"]
      },
      {
          test:/\.(jpg|png|gif)$/,
          use:['url-loader']
      }
		]
	},
	plugins: [
		new HtmlWebpackPlugin({
			template: './src/index.html',
			filename: 'index.html'
		}),
		// 热加载插件，webpack自带
		new Webpack.HotModuleReplacementPlugin()

	]
}